<template>
  <div v-if="getShow" class="modern-forget-password-wrapper">
    <div class="modern-forget-password-container">
      <!-- 步骤指示器 -->
      <div class="steps-container">
        <div class="steps">
          <div
            v-for="(step, index) in steps"
            :key="index"
            class="step"
            :class="{
              active: currentStep === index,
              completed: currentStep > index,
              disabled: currentStep < index,
            }"
          >
            <div class="step-number">
              <span v-if="currentStep > index">✓</span>
              <span v-else>{{ index + 1 }}</span>
            </div>
            <div class="step-label">{{ step.label }}</div>
          </div>
        </div>
      </div>

      <!-- 步骤内容 -->
      <div class="step-content">
        <!-- 步骤1：手机验证 -->
        <div v-if="currentStep === 0" class="step-form">
          <div class="form-header">
            <h2>{{ t('sys.login.forgetPassword') }}</h2>
            <p>{{ t('sys.login.enterPhoneToReset') }}</p>
          </div>

          <form @submit.prevent="handleStep1Submit" class="floating-form">
            <div class="input-group">
              <a-popover
                :visible="contactValidation && !contactValidation.isValid && contactValidation.show"
                placement="right"
                trigger="manual"
                :overlay-style="{ maxWidth: '300px' }"
              >
                <template #content>
                  <div class="validation-popover">
                    <ExclamationCircleOutlined class="error-icon" />
                    <span>{{ contactValidation?.message }}</span>
                  </div>
                </template>
                <input
                  id="contact"
                  v-model.trim="formData.contact"
                  type="text"
                  autocomplete="off"
                  @input="onContactInput"
                  @focus="handleFocus"
                  @blur="handleContactBlur"
                  required
                />
              </a-popover>
              <label for="contact" :class="{ focused: formData.contact }">{{ t('sys.login.contact') }}</label>
            </div>

            <div class="input-group sms-input-group">
              <a-popover
                :visible="verificationCodeValidation && !verificationCodeValidation.isValid && verificationCodeValidation.show"
                placement="right"
                trigger="manual"
                :overlay-style="{ maxWidth: '300px' }"
              >
                <template #content>
                  <div class="validation-popover">
                    <ExclamationCircleOutlined class="error-icon" />
                    <span>{{ verificationCodeValidation?.message }}</span>
                  </div>
                </template>
                <input
                  id="verificationCode"
                  v-model.trim="formData.verificationCode"
                  type="text"
                  autocomplete="off"
                  @input="onVerificationCodeInput"
                  @focus="handleFocus"
                  @blur="handleVerificationCodeBlur"
                  required
                />
              </a-popover>
              <label for="verificationCode" :class="{ focused: formData.verificationCode }">{{ t('sys.login.verificationCode') }}</label>
              <button
                type="button"
                class="sms-button"
                @click="sendVerificationCode"
                :disabled="!contactValidation?.isValid || smsCountdown > 0"
                :class="{ loading: smsCountdown === -1 }"
              >
                <span v-if="smsCountdown === -1">
                  <LoadingOutlined class="loading-icon" />
                  发送中...
                </span>
                <span v-else-if="smsCountdown > 0">{{ smsCountdown }}s</span>
                <span v-else>{{ t('sys.login.sendCode') }}</span>
              </button>
            </div>

            <button type="submit" class="submit-btn" :disabled="!isStep1Valid || loading" :class="{ loading: loading }">
              <span v-if="!loading">{{ t('sys.login.nextStep') }}</span>
              <span v-else>{{ t('sys.login.verifying') }}</span>
              <LoadingOutlined v-if="loading" class="loading-icon" />
            </button>
          </form>
        </div>

        <!-- 步骤2：重置密码 -->
        <div v-if="currentStep === 1" class="step-form">
          <div class="form-header">
            <h2>{{ t('sys.login.resetPassword') }}</h2>
            <p>{{ t('sys.login.enterNewPassword') }}</p>
          </div>

          <form @submit.prevent="handleStep2Submit" class="floating-form">
            <div class="input-group">
              <input id="username" v-model="formData.username" type="text" disabled class="disabled-input" />
              <label for="username" class="focused">{{ t('sys.login.userName') }}</label>
            </div>

            <div class="input-group">
              <a-popover
                :visible="passwordValidation.show && formData.password && formData.password.trim() !== ''"
                placement="right"
                trigger="manual"
                :overlay-style="{ maxWidth: '350px' }"
              >
                <template #content>
                  <div class="password-strength-popover">
                    <div class="strength-header">
                      <span>密码强度要求：</span>
                      <span class="strength-level" :class="passwordStrength.level">{{ passwordStrength.text }}</span>
                    </div>
                    <div class="strength-bar">
                      <div class="strength-fill" :class="passwordStrength.level"></div>
                    </div>
                    <div class="password-requirements">
                      <div class="requirement" :class="{ met: passwordRequirements.length }">
                        <CheckOutlined v-if="passwordRequirements.length" />
                        <CloseOutlined v-else />
                        至少6位
                      </div>
                      <div class="requirement" :class="{ met: passwordRequirements.uppercase }">
                        <CheckOutlined v-if="passwordRequirements.uppercase" />
                        <CloseOutlined v-else />
                        大写字母
                      </div>
                      <div class="requirement" :class="{ met: passwordRequirements.lowercase }">
                        <CheckOutlined v-if="passwordRequirements.lowercase" />
                        <CloseOutlined v-else />
                        小写字母
                      </div>
                      <div class="requirement" :class="{ met: passwordRequirements.number }">
                        <CheckOutlined v-if="passwordRequirements.number" />
                        <CloseOutlined v-else />
                        数字
                      </div>
                      <div class="requirement" :class="{ met: passwordRequirements.special }">
                        <CheckOutlined v-if="passwordRequirements.special" />
                        <CloseOutlined v-else />
                        特殊符号
                      </div>
                    </div>
                  </div>
                </template>
                <input
                  id="password"
                  v-model.trim="formData.password"
                  :type="showPassword ? 'text' : 'password'"
                  autocomplete="off"
                  @input="handlePasswordInput"
                  @focus="handleFocus"
                  @blur="handlePasswordBlur"
                  required
                />
              </a-popover>
              <label for="password" :class="{ focused: formData.password }">{{ t('sys.login.newPassword') }}</label>
              <button type="button" class="password-toggle" @click="togglePassword" :class="{ active: showPassword }">
                <EyeOutlined v-if="!showPassword" />
                <EyeInvisibleOutlined v-else />
              </button>
            </div>

            <div class="input-group">
              <a-popover
                :visible="confirmPasswordValidation && !confirmPasswordValidation.isValid && confirmPasswordValidation.show"
                placement="right"
                trigger="manual"
                :overlay-style="{ maxWidth: '300px' }"
              >
                <template #content>
                  <div class="validation-popover">
                    <ExclamationCircleOutlined class="error-icon" />
                    <span>{{ confirmPasswordValidation?.message }}</span>
                  </div>
                </template>
                <input
                  id="confirmPassword"
                  v-model.trim="formData.confirmPassword"
                  :type="showConfirmPassword ? 'text' : 'password'"
                  autocomplete="off"
                  @input="onConfirmPasswordInput"
                  @focus="handleFocus"
                  @blur="handleConfirmPasswordBlur"
                  required
                />
              </a-popover>
              <label for="confirmPassword" :class="{ focused: formData.confirmPassword }">{{ t('sys.login.confirmPassword') }}</label>
              <button type="button" class="password-toggle" @click="toggleConfirmPassword" :class="{ active: showConfirmPassword }">
                <EyeOutlined v-if="!showConfirmPassword" />
                <EyeInvisibleOutlined v-else />
              </button>
            </div>

            <div class="step-buttons">
              <button type="button" class="back-btn" @click="prevStep">
                {{ t('sys.login.prevStep') }}
              </button>
              <button type="submit" class="submit-btn" :disabled="!isStep2Valid || loading" :class="{ loading: loading }">
                <span v-if="!loading">{{ t('sys.login.resetPassword') }}</span>
                <span v-else>{{ t('sys.login.resetting') }}</span>
                <LoadingOutlined v-if="loading" class="loading-icon" />
              </button>
            </div>
          </form>
        </div>

        <!-- 步骤3：完成 -->
        <div v-if="currentStep === 2" class="step-form">
          <div class="success-container">
            <div class="success-inner">
              <div class="success-icon">
                <CheckCircleOutlined />
              </div>
              <div class="form-header">
                <h2>{{ t('sys.login.resetSuccess') }}</h2>
                <p>{{ t('sys.login.passwordResetSuccess') }}</p>
              </div>

              <div class="countdown-info">
                <p>{{ t('sys.login.redirectToLogin', [countdown]) }}</p>
              </div>

              <button type="button" class="submit-btn" @click="finish">
                {{ t('sys.login.backToLogin') }}
              </button>
            </div>
          </div>
        </div>
      </div>

      <!-- 返回登录链接 -->
      <div class="form-footer">
        <span>{{ t('sys.login.rememberPassword') }}</span>
        <a href="#" @click.prevent="setLoginState(LoginStateEnum.LOGIN)">
          {{ t('sys.login.backSignIn') }}
        </a>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { reactive, ref, onMounted, computed, unref, watch } from 'vue';
  import {
    EyeOutlined,
    EyeInvisibleOutlined,
    ExclamationCircleOutlined,
    LoadingOutlined,
    CheckCircleOutlined,
    CheckOutlined,
    CloseOutlined,
  } from '@ant-design/icons-vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { LoginStateEnum, useLoginState, SmsEnum } from './useLogin';
  import { phoneVerify, passwordChange, getCaptcha, verifyCodeEmail } from '/@/api/sys/user';

  const { t } = useI18n();
  const { createMessage: $message } = useMessage();
  const { setLoginState, getLoginState } = useLoginState();

  // 控制组件显示
  const getShow = computed(() => unref(getLoginState) === LoginStateEnum.RESET_PASSWORD);

  // 进入忘记密码页面时重置表单和步骤
  watch(getShow, (show) => {
    if (show) {
      formData.contact = '';
      formData.verificationCode = '';
      formData.username = '';
      formData.password = '';
      formData.confirmPassword = '';
      currentStep.value = 0;
      smsCountdown.value = 0;
      showPassword.value = false;
      showConfirmPassword.value = false;
      countdown.value = 5;
      // 其他状态如有也可重置
    }
  });

  // 步骤配置
  const steps = [{ label: t('sys.login.phoneVerification') }, { label: t('sys.login.resetPassword') }, { label: t('sys.login.complete') }];

  // 表单数据
  const formData = reactive({
    contact: '',
    verificationCode: '',
    username: '',
    password: '',
    confirmPassword: '',
  });

  // 状态管理
  const currentStep = ref(0);
  const loading = ref(false);
  const smsCountdown = ref(0);
  const showPassword = ref(false);
  const showConfirmPassword = ref(false);
  const countdown = ref(5);

  // 验证状态
  const isStep1Valid = ref(false);
  const isStep2Valid = ref(false);
  const contactValidation = ref<{ isValid: boolean; type: string | null; message: string; show: boolean } | null>(null);
  const verificationCodeValidation = ref<{ isValid: boolean; message: string; show: boolean } | null>(null);
  const confirmPasswordValidation = ref<{ isValid: boolean; message: string; show: boolean } | null>(null);

  // 密码强度验证
  const passwordValidation = reactive({
    show: false,
  });

  const passwordStrength = computed(() => {
    const password = formData.password;
    if (!password) return { level: 'weak', text: '弱' };

    const requirements = passwordRequirements.value;
    const metCount = Object.values(requirements).filter(Boolean).length;

    if (metCount >= 4 && password.length >= 8) return { level: 'strong', text: '强' };
    if (metCount >= 3 && password.length >= 6) return { level: 'medium', text: '中' };
    return { level: 'weak', text: '弱' };
  });

  const passwordRequirements = computed(() => {
    const password = formData.password;
    return {
      length: password.length >= 6,
      uppercase: /[A-Z]/.test(password),
      lowercase: /[a-z]/.test(password),
      number: /\d/.test(password),
      special: /[!@#$%^&*(),.?":{}|<>]/.test(password),
    };
  });

  // 联系方式验证 - 智能判断
  const validateContact = (contact: string) => {
    // 判断是否为纯数字（手机号）
    const isAllNumbers = /^\d+$/.test(contact);
    // 判断是否包含@或字母（邮箱）
    const hasEmailChars = /[@a-zA-Z]/.test(contact);

    if (isAllNumbers) {
      // 纯数字按手机号验证
      const phonePattern = /^1[3-9]\d{9}$/;
      if (phonePattern.test(contact)) {
        return { isValid: true, type: 'phone', message: '手机号格式正确', show: false };
      } else {
        return { isValid: false, type: 'phone', message: '请输入有效的手机号（11位数字）', show: false };
      }
    } else if (hasEmailChars) {
      // 包含@或字母按邮箱验证
      const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
      if (emailPattern.test(contact)) {
        return { isValid: true, type: 'email', message: '邮箱格式正确', show: false };
      } else {
        return { isValid: false, type: 'email', message: '请输入有效的邮箱地址', show: false };
      }
    } else {
      return { isValid: false, type: null, message: '请输入有效的手机号或邮箱地址', show: false };
    }
  };

  // 验证码验证
  const validateVerificationCode = (code: string) => {
    const isValid = code.trim().length >= 4;
    return {
      isValid,
      message: isValid ? '验证码格式正确' : '请输入有效的验证码',
      show: false,
    };
  };

  // 确认密码验证
  const validateConfirmPassword = (confirmPassword: string) => {
    const isValid = confirmPassword === formData.password;
    return {
      isValid,
      message: isValid ? '密码确认正确' : '两次输入的密码不一致',
      show: false,
    };
  };

  // 步骤1验证
  const validateStep1 = () => {
    const hasContact = contactValidation.value?.isValid || false;
    const hasVerificationCode = verificationCodeValidation.value?.isValid || false;
    isStep1Valid.value = hasContact && hasVerificationCode;
  };

  // 步骤2验证
  const validateStep2 = () => {
    const hasPassword = formData.password.trim().length > 0;
    const hasConfirmPassword = confirmPasswordValidation.value?.isValid || false;
    const isPasswordStrong = passwordStrength.value.level !== 'weak';

    isStep2Valid.value = hasPassword && hasConfirmPassword && isPasswordStrong;
  };

  // 处理输入框焦点
  const handleFocus = (event) => {
    const input = event.target;
    const label = input.nextElementSibling;

    // 添加一些炫酷的初始效果
    label.style.transform = 'translateY(-50%) translateX(0) rotate(0deg) scale(1)';
    label.style.opacity = '1';

    // 添加轻微的弹跳效果
    setTimeout(() => {
      label.style.transform = 'translateY(-50%) translateX(0) rotate(0deg) scale(1.05)';
      setTimeout(() => {
        label.style.transform = 'translateY(-50%) translateX(0) rotate(0deg) scale(1)';
        label.classList.add('focused');
      }, 100);
    }, 50);
  };

  // 处理输入框失焦
  const handleBlur = (event) => {
    const input = event.target;
    const label = input.nextElementSibling;

    if (!input.value) {
      // 先设置初始状态（向右移出）
      label.style.transform = 'translateY(-50%) translateX(100px) rotate(15deg) scale(0.8)';
      label.style.opacity = '0';

      // 短暂延迟后播放向左移入动画
      setTimeout(() => {
        label.classList.remove('focused');
        label.style.animation = 'labelSlideIn 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards';

        // 动画结束后清除样式并添加弹跳效果
        setTimeout(() => {
          label.style.animation = '';
          label.style.transform = '';
          label.style.opacity = '';

          // 添加最终的弹跳效果
          setTimeout(() => {
            label.style.transform = 'translateY(-50%) translateX(0) rotate(0deg) scale(1.1)';
            setTimeout(() => {
              label.style.transform = 'translateY(-50%) translateX(0) rotate(0deg) scale(1)';
            }, 150);
          }, 50);
        }, 600);
      }, 50);
    }
  };

  // 联系方式输入处理
  const onContactInput = () => {
    contactValidation.value = validateContact(formData.contact);
    validateStep1();
  };

  // 联系方式失焦处理 - 校验失败清空输入框
  const handleContactBlur = (event) => {
    handleBlur(event);
    if (formData.contact.trim()) {
      contactValidation.value = validateContact(formData.contact);
      if (!contactValidation.value.isValid) {
        contactValidation.value.show = true;
        // 清空联系方式输入框
        formData.contact = '';
      }
    }
    validateStep1();
  };

  // 验证码输入处理
  const onVerificationCodeInput = () => {
    verificationCodeValidation.value = validateVerificationCode(formData.verificationCode);
    validateStep1();
  };

  // 验证码失焦处理
  const handleVerificationCodeBlur = (event) => {
    handleBlur(event);
    if (formData.verificationCode.trim()) {
      verificationCodeValidation.value = validateVerificationCode(formData.verificationCode);
      if (!verificationCodeValidation.value.isValid) {
        verificationCodeValidation.value.show = true;
      }
    }
    validateStep1();
  };

  // 确认密码输入处理
  const onConfirmPasswordInput = () => {
    confirmPasswordValidation.value = validateConfirmPassword(formData.confirmPassword);
    validateStep2();
  };

  // 确认密码失焦处理 - 校验失败显示不清空
  const handleConfirmPasswordBlur = (event) => {
    handleBlur(event);
    if (formData.confirmPassword.trim()) {
      confirmPasswordValidation.value = validateConfirmPassword(formData.confirmPassword);
      if (!confirmPasswordValidation.value.isValid) {
        confirmPasswordValidation.value.show = true;
      }
    }
    validateStep2();
  };

  // 密码输入处理
  const handlePasswordInput = () => {
    passwordValidation.show = true;
    validateStep2();
  };

  const handlePasswordBlur = () => {
    passwordValidation.show = false;
  };

  // 切换密码显示
  const togglePassword = () => {
    showPassword.value = !showPassword.value;
  };

  const toggleConfirmPassword = () => {
    showConfirmPassword.value = !showConfirmPassword.value;
  };

  // 发送验证码
  const sendVerificationCode = async () => {
    if (!contactValidation.value?.isValid) {
      $message.error(t('sys.login.pleaseEnterContact'));
      return;
    }

    try {
      // 设置发送验证码按钮为加载状态
      smsCountdown.value = -1; // -1 表示加载中状态

      const contactType = contactValidation.value.type;

      if (contactType === 'email') {
        await verifyCodeEmail({ email: formData.contact, model: '2', username: formData.contact });
        $message.success('邮箱验证码已发送');
      } else if (contactType === 'phone') {
        await getCaptcha({ mobile: formData.contact, smsmode: SmsEnum.FORGET_PASSWORD });
        $message.success('短信验证码已发送');
      } else {
        $message.error('联系方式类型不正确');
        return;
      }

      // 发送成功后开始倒计时
      smsCountdown.value = 60;
      const timer = setInterval(() => {
        smsCountdown.value--;
        if (smsCountdown.value <= 0) {
          clearInterval(timer);
        }
      }, 1000);
    } catch (error: any) {
      $message.error(error?.message || t('sys.api.networkExceptionMsg'));
      // 发送失败时重置按钮状态
      smsCountdown.value = 0;
    }
  };

  // 输入验证
  const validateInput = () => {
    // 只做错误提示清理
    if (isStep1Valid.value && isStep2Valid.value) {
    }
  };

  // 步骤1提交
  const handleStep1Submit = async () => {
    // XSS 防护
    const xssPattern = /(~|\{|\}|"|'|<|>|\?)/g;
    if (xssPattern.test(formData.contact) || xssPattern.test(formData.verificationCode)) {
      $message.error(t('sys.login.xssWarning'));
      return;
    }

    try {
      loading.value = true;

      const contactType = contactValidation.value?.type;

      // 执行phoneVerify验证
      const result = await phoneVerify({
        [contactType === 'email' ? 'email' : 'phone']: formData.contact,
        smscode: formData.verificationCode,
      });

      console.log('result', result);

      if (result.success) {
        // phoneVerify返回username
        formData.username = result.result?.username || formData.contact;
        nextStep();
      } else {
        $message.error(result.message);
      }
    } catch (error: any) {
      $message.error(error.message || t('sys.api.networkExceptionMsg'));
    } finally {
      loading.value = false;
    }
  };

  // 在重置密码成功后写入 sessionStorage 并跳转到登录页
  const handleStep2Submit = async () => {
    // XSS 防护
    const xssPattern = /(~|\{|\}|"|'|<|>|\?)/g;
    if (xssPattern.test(formData.password) || xssPattern.test(formData.confirmPassword)) {
      $message.error(t('sys.login.xssWarning'));
      return;
    }

    // 密码确认验证
    if (formData.password !== formData.confirmPassword) {
      $message.error(t('sys.login.passwordNotMatch'));
      return;
    }

    // 密码强度验证
    if (passwordStrength.value.level === 'weak') {
      $message.error('密码强度不足，请满足所有要求');
      return;
    }

    try {
      loading.value = true;

      const contactType = contactValidation.value?.type;
      const result = await passwordChange({
        username: formData.username,
        password: formData.password,
        smscode: formData.verificationCode,
        [contactType === 'email' ? 'email' : 'phone']: formData.contact,
      });

      if (result.success) {
        // 写入 sessionStorage
        sessionStorage.setItem('register_username', formData.username);
        sessionStorage.setItem('register_password', formData.password);
        nextStep();
        startCountdown();
      } else {
        $message.error(result.message || t('sys.api.networkExceptionMsg'), 3);
      }
    } catch (error: any) {
      $message.error(error.message || t('sys.api.networkExceptionMsg'));
    } finally {
      loading.value = false;
    }
  };

  // 下一步
  const nextStep = () => {
    if (currentStep.value < steps.length - 1) {
      currentStep.value++;
    }
  };

  // 上一步
  const prevStep = () => {
    if (currentStep.value > 0) {
      currentStep.value--;
    }
  };

  // 完成
  const finish = () => {
    setLoginState(LoginStateEnum.LOGIN);
  };

  // 倒计时
  const startCountdown = () => {
    const timer = setInterval(() => {
      countdown.value--;
      if (countdown.value <= 0) {
        clearInterval(timer);
        finish();
      }
    }, 1000);
  };

  // 初始化
  onMounted(() => {
    validateStep1();
    validateStep2();
  });

  // 监听步骤变化
  watch(currentStep, (newStep) => {
    if (newStep === 0) {
      validateStep1();
    } else if (newStep === 1) {
      validateStep2();
    }
  });

  // 监听步骤变化
  watch(currentStep, (newStep) => {
    if (newStep === 0) {
      validateStep1();
    } else if (newStep === 1) {
      validateStep2();
    }
  });
</script>

<style scoped lang="less">
  .modern-forget-password-wrapper {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
  }

  .modern-forget-password-container {
    width: 480px;
    max-width: 480px;
    border-radius: 24px;
    padding: 48px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    position: relative;
    z-index: 1;
    animation: fadeInUp 0.6s ease-out;

    @keyframes fadeInUp {
      from {
        opacity: 0;
        transform: translateY(30px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }
  }

  // 步骤指示器
  .steps-container {
    margin-bottom: 32px;
  }

  .steps {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;

    &::before {
      content: '';
      position: absolute;
      top: 20px;
      left: 20px;
      right: 20px;
      height: 2px;
      background: #e5e7eb;
      z-index: 0;
    }
  }

  .step {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
    transition: all 0.3s ease;

    &.active {
      .step-number {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        transform: scale(1.1);
      }
      .step-label {
        color: #667eea;
        font-weight: 600;
      }
    }

    &.completed {
      .step-number {
        background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        color: white;
      }
      .step-label {
        color: #10b981;
      }
    }

    &.disabled {
      .step-number {
        background: #f3f4f6;
        color: #9ca3af;
      }
      .step-label {
        color: #9ca3af;
      }
    }
  }

  .step-number {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }

  .step-label {
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    transition: all 0.3s ease;
  }

  // 步骤内容
  .step-content {
    min-height: 300px;
  }

  .step-form {
    width: 100%;
    min-height: 420px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
  }

  @keyframes fadeIn {
    from {
      opacity: 0;
      transform: translateX(20px);
    }
    to {
      opacity: 1;
      transform: translateX(0);
    }
  }

  .form-header {
    text-align: center;
    margin-bottom: 40px;

    h2 {
      color: #2c3e50;
      font-size: 32px;
      margin-bottom: 12px;
      font-weight: 700;
      background: linear-gradient(135deg, #667eea, #764ba2);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
    }

    p {
      color: #7f8c8d;
      font-size: 16px;
      margin: 0;
    }
  }

  // 成功页面
  .success-container {
    text-align: center;
    padding: 40px 0;
    min-height: 320px;
    width: 100%;
    margin: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }

  .success-inner {
    width: 100%;
    max-width: none;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0;
  }
  .success-inner .form-header,
  .success-inner .countdown-info,
  .success-inner .submit-btn {
    width: 100%;
    box-sizing: border-box;
  }

  .success-icon {
    font-size: 80px;
    color: #27ae60;
    margin-bottom: 24px;
    animation: bounceIn 0.6s ease-out;
  }

  @keyframes bounceIn {
    0% {
      opacity: 0;
      transform: scale(0.3);
    }
    50% {
      opacity: 1;
      transform: scale(1.05);
    }
    70% {
      transform: scale(0.9);
    }
    100% {
      opacity: 1;
      transform: scale(1);
    }
  }

  .countdown-info {
    margin: 24px 0;
    padding: 16px;
    background: rgba(39, 174, 96, 0.1);
    border-radius: 16px;
    border: 1px solid rgba(39, 174, 96, 0.2);

    p {
      margin: 0;
      color: #27ae60;
      font-size: 14px;
      font-weight: 500;
    }
  }

  // 表单样式
  .floating-form {
    display: flex;
    flex-direction: column;
  }

  .input-group {
    position: relative;
    margin-bottom: 32px;

    &.sms-input-group {
      input {
        padding-right: 100px !important;
      }

      .sms-button {
        position: absolute;
        right: 16px;
        top: 50%;
        transform: translateY(-50%);
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        border: none;
        padding: 8px 16px;
        border-radius: 8px;
        font-size: 12px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.3s ease;
        min-width: 80px;

        &:hover:not(:disabled) {
          transform: translateY(-50%) scale(1.05);
          box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
        }

        &:disabled {
          opacity: 0.6;
          cursor: not-allowed;
        }

        &.loading {
          opacity: 0.6;
          cursor: not-allowed;

          .loading-icon {
            margin-right: 4px;
            animation: spin 1s linear infinite;
          }

          @keyframes spin {
            from {
              transform: rotate(0deg);
            }
            to {
              transform: rotate(360deg);
            }
          }
        }
      }
    }

    &.disabled-input {
      input {
        background: #f9fafb;
        color: #6b7280;
        cursor: not-allowed;
      }
    }
  }

  .input-group input {
    width: 100%;
    padding: 16px 20px;
    border: 2px solid #e1e8ed;
    border-radius: 16px;
    font-size: 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(255, 255, 255, 0.9);
    color: #2c3e50;
    outline: none;

    &:focus {
      border-color: #667eea;
      box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
      background: rgba(255, 255, 255, 1);
    }

    &:valid {
      border-color: #27ae60;
    }

    &.disabled-input {
      background: #f9fafb;
      color: #6b7280;
      cursor: not-allowed;
    }
  }

  .input-group label {
    position: absolute;
    left: 35px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    padding: 0 8px;
    color: #95a5a6;
    font-size: 18px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    border-radius: 4px;
    font-weight: 400;
    letter-spacing: 0.2px;

    &.focused,
    &:has(+ input:valid) {
      transform: translateY(-50%) translateX(100px) rotate(15deg) scale(0.8);
      opacity: 0;
      animation: labelSlideOut 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
    }

    @keyframes labelSlideOut {
      0% {
        transform: translateY(-50%) translateX(0) rotate(0deg) scale(1);
        opacity: 1;
      }
      25% {
        transform: translateY(-50%) translateX(25px) rotate(-5deg) scale(1.1);
        opacity: 0.8;
      }
      50% {
        transform: translateY(-50%) translateX(50px) rotate(8deg) scale(0.9);
        opacity: 0.6;
      }
      75% {
        transform: translateY(-50%) translateX(75px) rotate(-3deg) scale(0.85);
        opacity: 0.3;
      }
      100% {
        transform: translateY(-50%) translateX(100px) rotate(15deg) scale(0.8);
        opacity: 0;
      }
    }

    @keyframes labelSlideIn {
      0% {
        transform: translateY(-50%) translateX(100px) rotate(-15deg) scale(0.8);
        opacity: 0;
      }
      60% {
        transform: translateY(-50%) translateX(15px) rotate(8deg) scale(1.2);
        opacity: 0.8;
      }
      80% {
        transform: translateY(-50%) translateX(-8px) rotate(-3deg) scale(1.1);
        opacity: 0.9;
      }
      90% {
        transform: translateY(-50%) translateX(3px) rotate(1deg) scale(1.05);
        opacity: 0.95;
      }
      100% {
        transform: translateY(-50%) translateX(0) rotate(0deg) scale(1);
        opacity: 1;
      }
    }
  }

  .password-toggle {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #95a5a6;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.3s ease;

    &:hover {
      color: #667eea;
      background: rgba(102, 126, 234, 0.1);
    }

    &.active {
      color: #667eea;
    }
  }

  // 错误消息
  .error-message {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 12px;
    color: #dc2626;
    font-size: 14px;
    animation: shake 0.5s ease-in-out;
    margin-bottom: 16px;

    @keyframes shake {
      0%,
      100% {
        transform: translateX(0);
      }
      25% {
        transform: translateX(-5px);
      }
      75% {
        transform: translateX(5px);
      }
    }
  }

  // 按钮样式
  .step-buttons {
    display: flex;
    gap: 16px;
    margin-top: 8px;
  }

  .back-btn {
    flex: 1;
    padding: 18px 32px;
    border: 2px solid #e1e8ed;
    border-radius: 16px;
    background: white;
    color: #6b7280;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
    min-width: 0;
    &:hover {
      border-color: #667eea;
      background: rgba(102, 126, 234, 0.05);
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
    }
  }

  .submit-btn {
    flex: 1;
    padding: 18px 32px;
    border: none;
    border-radius: 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    margin-top: 0;
    text-align: center;
    min-width: 0;
    &:hover:not(:disabled) {
      transform: translateY(-2px);
      box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
    }
    &:disabled {
      opacity: 0.6;
      cursor: not-allowed;
      transform: none;
      box-shadow: none;
    }
    &.loading {
      pointer-events: none;
    }
    .loading-icon {
      margin-left: 8px;
      animation: spin 1s linear infinite;
    }
    @keyframes spin {
      from {
        transform: rotate(0deg);
      }
      to {
        transform: rotate(360deg);
      }
    }
  }

  // Popover 样式
  .validation-popover {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #e74c3c;
    font-size: 14px;

    .error-icon {
      color: #e74c3c;
      font-size: 16px;
    }
  }

  // 表单页脚
  .form-footer {
    text-align: center;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid #e1e8ed;
    color: #7f8c8d;
    font-size: 14px;

    a {
      color: #667eea;
      text-decoration: none;
      font-weight: 600;
      margin-left: 4px;
      transition: all 0.3s ease;

      &:hover {
        color: #764ba2;
        text-decoration: underline;
      }
    }
  }

  // 密码强度弹窗
  .password-strength-popover {
    padding: 16px;
    max-width: 300px;
  }

  .strength-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 600;
  }

  .strength-level {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;

    &.weak {
      background: #fef2f2;
      color: #dc2626;
    }

    &.medium {
      background: #fffbeb;
      color: #d97706;
    }

    &.strong {
      background: #f0fdf4;
      color: #16a34a;
    }
  }

  .strength-bar {
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    margin-bottom: 12px;
    overflow: hidden;
  }

  .strength-fill {
    height: 100%;
    transition: all 0.3s ease;

    &.weak {
      width: 33.33%;
      background: #dc2626;
    }

    &.medium {
      width: 66.66%;
      background: #d97706;
    }

    &.strong {
      width: 100%;
      background: #16a34a;
    }
  }

  .password-requirements {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .requirement {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #6b7280;

    &.met {
      color: #16a34a;
    }

    .anticon {
      font-size: 12px;
    }
  }

  // 响应式设计
  @media (max-width: 640px) {
    .modern-forget-password-container {
      padding: 32px 24px;
      margin: 16px;
    }

    .steps {
      .step-label {
        font-size: 10px;
      }
    }

    .step-buttons {
      flex-direction: column;
    }

    .back-btn,
    .submit-btn {
      flex: none;
    }
  }

  // 深色模式适配
  html[data-theme='dark'] & {
    .modern-forget-password-container {
      background: rgba(17, 24, 39, 0.8);
      border-color: rgba(255, 255, 255, 0.1);
    }

    .form-header h2 {
      color: #f9fafb;
    }

    .form-header p {
      color: #d1d5db;
    }

    .input-group input {
      background: rgba(31, 41, 55, 0.8);
      border-color: #374151;
      color: #f9fafb;

      &:focus {
        background: rgba(31, 41, 55, 1);
        border-color: #667eea;
        box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
      }
    }

    .input-group label {
      background: transparent;
      color: #9ca3af;

      &.focused {
        color: #667eea;
      }
    }

    .back-btn {
      background: rgba(31, 41, 55, 0.8);
      border-color: #374151;
      color: #d1d5db;

      &:hover {
        background: rgba(55, 65, 81, 0.8);
      }
    }

    .submit-btn {
      &:disabled {
        opacity: 0.6;
        cursor: not-allowed;
        transform: none;
        box-shadow: none;
      }
    }

    .sms-button {
      &:disabled {
        opacity: 0.6;
        cursor: not-allowed;
      }

      &.loading {
        opacity: 0.6;
        cursor: not-allowed;
      }
    }

    .form-footer {
      border-color: #374151;
      color: #d1d5db;
    }

    .countdown-info {
      background: rgba(31, 41, 55, 0.8);
      border-color: #374151;

      p {
        color: #d1d5db;
      }
    }

    // 密码强度弹窗暗色模式
    .password-strength-popover {
      background: rgba(31, 41, 55, 0.95);
      border-color: #374151;
      color: #f9fafb;

      .strength-header {
        color: #f9fafb;
      }

      .strength-bar {
        background: #4b5563;
      }

      .requirement {
        color: #9ca3af;

        &.met {
          color: #10b981;
        }
      }
    }

    // 验证弹窗暗色模式
    .validation-popover {
      background: rgba(31, 41, 55, 0.95);
      border-color: #374151;
      color: #f9fafb;
    }
  }

  // 暗色模式下输入框样式，确保聚焦时也是深色背景
  .dark .modern-forget-password-wrapper .input-group input,
  .dark .modern-forget-password-wrapper .input-group input:focus {
    background: #23272f !important;
    color: #fff !important;
    border-color: #444a58 !important;
    box-shadow: none !important;
  }

  .dark .modern-forget-password-wrapper .input-group input:focus {
    border-color: #667eea !important;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.15) !important;
  }

  // 暗色模式下标签样式，确保没有背景
  .dark .modern-forget-password-wrapper .input-group label {
    background: transparent !important;
  }

  // 暗色模式下按钮样式，确保禁用状态使用透明度
  .dark .modern-forget-password-wrapper .submit-btn:disabled {
    opacity: 0.6 !important;
    cursor: not-allowed !important;
  }

  .dark .modern-forget-password-wrapper .sms-button:disabled,
  .dark .modern-forget-password-wrapper .sms-button.loading {
    opacity: 0.6 !important;
    cursor: not-allowed !important;
  }
</style>
